﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Configuration;

using Microsoft.Forums.MicrosoftForumsProvider;
using Microsoft.Forums.SyncService;
using Microsoft.Forums.OfflineStore;
using System.Collections.ObjectModel;
using Microsoft.Forums.ForumsClient.Models;
using Microsoft.Forums.ForumsProvider;
using Microsoft.Forums.ForumsClient.Controllers;

namespace Microsoft.Forums.ForumsClient
{
    /// <summary>
    /// Main Application Window
    /// </summary>
    public partial class AppWindow : Window
    {

        AppWindowController controller;

        /// <summary>
        ///  Get the application level data Model.
        /// </summary>
        public static AppDataModel DataModel
        {
            get
            {
                return AppDataModel.Instance;
            }
        }

        /// <summary>
        ///  Get the application.
        /// </summary>
        public static App CurrentApplication
        {
            get
            {
                return (App.Current as App);
            }
        }

        /// <summary>
        ///  AppWindow constructor.
        /// </summary>
        public AppWindow()
        {
            InitializeComponent();

            

            // Adjust the Width and Height to fit the screen resolution.
            if (Width >= System.Windows.SystemParameters.PrimaryScreenWidth)
                Width = System.Windows.SystemParameters.PrimaryScreenWidth - 30;

            if (Height >= System.Windows.SystemParameters.PrimaryScreenHeight)
                Height = System.Windows.SystemParameters.PrimaryScreenHeight - 30;
            
            controller = new AppWindowController(this,AppDataModel.Instance);
        }

        protected override void OnContentRendered(EventArgs e)
        {
            base.OnContentRendered(e);
            controller.Initialize();
        }

        
        #region SynchronizeForum Command Handlers
        private void SynchronizeForum_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanSynchronizeForum;
        }

        private void SynchronizeForum_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.SynchronizeForum();
        }
        #endregion

        #region SynchronizeAllForums Command Handlers
        private void SynchronizeAllForums_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanSynchronizeAllForums;
        }

        private void SynchronizeAllForums_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.SynchronizeAllForums();
        }
        #endregion

        #region UnsubscribeForum Command Handlers
        private void UnsubscribeForum_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanUnsubscribeForum;
        }

        private void UnsubscribeForum_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.UnsubscribeForum();
        }
        #endregion

        #region LogOn Command Handlers
        private void LogOn_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanLogOn;
        }

        private void LogOn_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.LogOn();
        }
        #endregion

        #region ShowSubscribeDialog Command Handlers
        private void ShowSubscribeDialog_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanShowSubscribeDialog;
        }

        private void ShowSubscribeDialog_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.ShowSubscribeDialog();
        }
        #endregion

        #region Show Options Dialog Command Handlers

        private void ShowOptionsSettingsDialog_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanShowOptionsDialog;
        }

        private void ShowOptionsSettingsDialog_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.ShowOptionsDialog();
        }
        #endregion

        #region ChangeTheme Command Handlers
        private void ChangeTheme_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanChangeTheme;
        }

        private void ChangeTheme_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.ChangeTheme();
        }
        #endregion


        #region Show Create Thread Form Command Handlers
        private void ShowCreateThreadForm_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = controller.CanShowCreateThreadForm;
        }

        private void ShowCreateThreadForm_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            controller.ShowCreateThreadForm();
        }
        #endregion

 
    }
}
